<?php
/**
 * Queue implementation.
 *
 * @version $Id: Queue.php,v 1.2 2011-05-06 05:18:54 herve Exp $
 * @copyright 2011
 */
class Queue {
	/** 
	* @var array The Stack data. 
	* @access private 
	*/
	private $_queue= array ();
	
	/** 
	* Push the argument onto the stack. 
	* @param mixed $content The element to be pushed onto the stack. 
	*/
	public function enqueue(&$element) {
		if ($element != null)
			array_push($this->_queue, $element);
	}

	/** 
	* Push the objects contains in array argument onto the stack. 
	* @param mixed $elements The element to be pushed onto the stack. 
	*/
	public function enqueue_all($elements) {
		if (is_array($elements)) {
			foreach ($elements as $element)
				$this->enqueue($element);
		} else {
			$this->enqueue($elements);
		}
	}

	/** 
	* Pop the Stack. 
	* @returns mixed The reference to the popped element. 
	*/
	public function & dequeue() {
		$element= & $this->top();
		array_shift ($this->_queue);
		return $element;
	}

	/** 
	* Returns a reference to the top of the stack. 
	* @returns mixed A reference to the top of the stack. 
	*/
	public function & top() {
		$count= count($this->_queue);
		// Prevent bad reference pointer 
		if ($count == 0) {
			return null;
		}
		return $this->_queue[0];
	}

	/** 
	* Get the lenght of the Stack. 
	* @returns int The lenght of the Stack. 
	*/
	public function get_length() {
		return count($this->_queue);
	}
	
	public function is_empty(){
		return $this->get_length() <= 0;
	}
	
	public function clear(){
		$this->_queue= array ();
	}
}

?>
